Puyo Puyo~n Story Mode Restoration

.: Introduction :.
  The one (arguably only) advantage to romhacking is you can make financially disastrous decisions.  The game's story is now fully* voiced...growing the ROM ~226% in the process.
  (*Practice mode's ending never had voice from the looks (sounds?) of it.)

  In addition, although the scripts themselves remain untouched, a number of script commands were tampered with so they function properly--or in most cases, at all.  These include:
  F322: vertical flip (despite microcode limitations)
  F340: colorize child, used to darken BG, FG, and characters
  F341 & F342: BG animations that were hardcoded, cause of water effects in story mode
  F352: play SFX (aka voice)
  F357: fade out music over time; fixed so the fade actually occurs over time

  Other random bug fixes include supporting MPAL, music is halted between multi-part chapters, the row of tiles below the textbox now have lower priority than Carbuncle's magic, 90% of the teleport effect restored (colorized instead of value-modifying), and alternate story chapters for lower difficulties were reintroduced, alongside ability selection in stage 15 below normal.

  Unnecessary additions are also included ;*)
  Story mode music is more muted so all this voice can be heard better, and that typewriter tick has gone the way of the typewriter.  You can quit the credits early even in story mode, the default combiner settings are changed so thresholding black as alpha also aliases edges (under normal lighting), and the large puyo on the title screen boings as it bounces.  The internal version has been updated to 2.0 and a timestamp was added to help differentiate patched files easier--especially if it's updated in the future when, say, the teleport effect is finalized.
  The one you'll hate the most though is reintroducing ending 3.  In other voiced versions, Arle & Carbuncle share a few lines at the end of the credits.  N64 has an unused story scene instead which would have played after the credits (index 0x47).  It's awkward and should rightfully remain cut, but now it's there and fully voiced.


.: Patching :.

  Apply the xdelta patch using the similarly named xdelta.  The patch will only apply to a ROM in native (big-endian) byteorder.

  Common Names
  	Puyo Puyo 4 - Puyo Puyon Party (Japan)
  	Puyo Puyo 4 - Puyo Puyo Party (J)

  Original File Checksums
  SHA-1
  	D5553182ECDA2EBA6076E7B04B900EF78B700FC5
  SHA-512
  	A363BD0EF13C25AD8A3911FD96B962AD6025485A2E586D944E645A8E94F2881778EE2AADCBA22917CEBE37457740E664B5876923598CDAE385C2DF5E6071CBEB

  Patched File Checksums
  SHA-1
  	830D30F2514A01C190DE089475888B4EF17D295A
  SHA-512
  	547E5BC3BCA773E6ECDA4F743653C0B8F5C679383976111BB7E0B24BC197CF4A0DEA25674F5427BCB9EB18FBF16D649DDC486CC051D137DBDACC5299E6B5F4FA


.: Notes :.
  Voice for story dialog is sourced from Dreamcast, downsampled to 22050Hz with lead-ins clipped, encoded in the N64's oddball VADPCM.  That places it in the neighborhood of the existing voices heard during gameplay.  Downsampling wasn't necessary, but the size-to-quality ratio really can't be rationalized.  It could be reduced further in all honesty.
  It's implemented as a fifth floating bank at the end of rdram, divided into sets of SFX corresponding to the script files.  Voice triggers within the script were already present, the handler itself NOP'd.

  A less noticeable change is the restoration of a few script commands.  The story scripts are mostly* the same, but the Dreamcast, PSX, and N64 games don't necessarily implement all of the scripts' commands.  Some just aren't relevant.  Key pitch seems specific to PSX, another audio command is only used on DC, the image stack works differently on DC vs anything else, etc.  Some are implemented differently too, like how heat effects may be stand-alone functions or just a phase difference of spooky, or Skeleton-T 64 rolls his own question mark instead of using the command for it.
  N64 ignores the BG effect commands--heat & spooky--but implements them differently, setting a callback function when the BG is loaded, largely because the same function is used to animate BGs in gameplay as well.  This causes a slight issue with Satan & Doppel's script.  The spooky effect is supposed to trigger halfway through when your friends are suppressed.  Likewise, Nohoho & Seriri* story BGs are erroneously animated.  The commands are now reimplemented.
  N64 also ignores a BG/FG/sprite colorizing effect probably because it's a pain in the butt to implement.  In a nutshell, the priority of different layers causes colorization commands to leak to everything following it in the display list, and the way they abused the combiner as a general multiplier for BG effects made it useless for what it's actually made for.  There's no one-size-fits-all solution for every subclass.  The final solution was a combination of monkeywrapped update functions and flags, plus a couple dirty hacks.  Kinda annoying, but fixed it in the end.
  (*Fight me over this.  I dare you.)

  Audio fade timers have an odd bug.  Instead of fading from the current volume, the timer +is+ the volume.  They very quickly fixed this by ignoring the time altogether and just fading from a static, current value.  Long story short, it behaves as expected now.

  Interestingly, all these bugged commands are sequential, at the end of the bank.  The debug crew must have been going from the top of the list to the bottom and ran out of time ;*)

  The teleport effect is an interesting case.
  The first issue is that the random bit effect isn't generated, though the image is present, and needed to be implemented from scratch.  It consists of generating children every so many frames, much like Harpy's notes.  The display function callback is shared with the main teleport light, but creation and update callbacks are written anew.  Priority levels are lowered randomly to achieve the effect of depth.
  Second issue is that in Kikimora_B the teleport effect switches off one event early.  The timer is built directly into the code, which works since the only other instance of a teleport is in the practice mode ending.  Raising the timer by the same value as the wait commands corrects this.
  The last is seriously problematic.  The source images are a smaller version of the Dreamcast image.  In neither case does it appear the actual color in the palette is used, relying on its intensity instead.  The visual difference lies in application.  On N64 they're only adding it as an overlay like any other tile, whitening anything above it.  Dreamcast modifies the HSV value of underlying layers, resulting in a gamma-rich glow.  The salmon color is only a byproduct of interaction with the background.
  It's possible to replicate this on N64 (mult each color in memory by pixel's intensity/255), just not easily within the confines of a precompiled binary's graphic pipeline without affecting 90% of everything else that's drawn.  Some of the best examples of exactly this effect are magical everythings in Ogre Battle 64.  Out of laziness, it was colorized orange-yellow instead.  Sorry about that.

  There's two slightly different final chapters.  Stages 15 & 16 (Satan & Doppel) (are supposed to) have difficulty-based variants, each with unique dialog.  On normal difficulty and above, you'll get SatanA (longer) and DoppelB (shorter).  The difference lies in that Doppel, not Satan, attacks your friends--the in-game justification why you can't use powers in the last couple stages.
  N64 didn't implement the difficulty change.  Not terribly sure it's applied in any other version either--though they all have these two blobs of story, otherwise where would the audio come from?  It's been reinserted, and changing the difficulty will affect which story chapter you view in-game and in the extras menu.

  Also, the voiceover at the end of the credits was spun-off as a story chapter in N64, ultimately unused.  Can't argue with that, it's pretty clumsy.

  DC & PSX source audio for the story's opening muxed VO and BGM together.  Voice is centered, and phase cancellation works about as well as expected.  Ideally, the VO would be triggered alongside the existing BGM via cues (like the captions were), but as it stands the entire track had to be inserted.  The bloat is real; that audio track alone is 9% of the total audio size (though the original was 17.9MB, bit hard to complain).  If the voice could be clipped out, each sample would only be a kilobyte or so.
  Satan's magic once again uses its palette, but is only applied as an overlay instead of a lighting effect.  Due to discrepancies when the text suddenly became captions, those have been repressed.

  I'd like to shake the hand of the programmer who sorted out the atrocious trash fire that was Sun's codebase.  A true unsung hero.  It's almost object-oriented in its approach.
  If only the gameplay wasn't so blasted annoying...  Is it asking so much that there is any margin time at all?  The story & art direction are its redeeming points.
  Bomb Puyo is a potato.  Worst mode ever.


.: Unfixed Issues in Original :.
  Panotty's knee has a single line of interlaced pixels--a chunk of his knee shifted to the side.  This isn't in the source image, and it's not the only case of this type of error.  It's frustrating to fix this kind of thing when it can be corrected at all; don't intend on ever addressing it.

  Edges of textboxes tend to overlap their fill, leaving a dark band of varying width on the right edge.  It's probably not that hard of a fix, or a necessary one.

  When playing multi-part chapters, there's no downtime between displaying the second part and the first.  Transitioning from defeating Rulue and entering the tent, there will be a few frames before the script hits the colorization commands to darken the background.  You won't notice this when coming into the chapter from the menu or from a save thanks to the fade in.
  Preventing that would be difficult to say the least without rewriting the script, but a related bug which didn't stop the music between chapter parts was corrected.

  Likewise, there will be a frame or two in the first part of the ending when Carbuncle's magic will be cleared and the screen will not be white.  To correct this would require making a global whiteout effect outside of the scripting engine, destroyed by something outside the class running the script.  Not impossible, but tedious.
  However, a related glitch was corrected, lowering the priority of the boxes at the bottom of the screen so they aren't drawn above Carbuncle's magic whiteout effect.

  Wiggle and wobble effects presumed that the margins at the edge of the screen weren't visible, outside the ~5% "action-safe area".  If you aren't using an analog screen (or not framing your digital out) you can see the gap this leaves.  "Correcting" this might seem simple but it's non-trivial in practice.  Note that if your digital-out has a phase difference with the actual framerate you likely won't see the effect at all.

  Didn't add in any of the lighting effects (HSV value modifiers) missing from DC (like at match start, Carbuncle disappearing in the opening, the teleport animation, etc.) or partially-transparent "shadows" of chain counts, win messages, and cleared puyos; nor changed any of the dialog timing (some wait timers might as well not exist).  Nothing preventing that of course--most of those anims already exist for story mode--but felt well outside the scope of a VO story patch.

  Once a tile has been loaded and indexed (usually when it's first set), it won't be reloaded when a clipped part becomes visible unless its address changed.  It's likely an issue with the microcode itself; other titles using sprite microcodes have similar problems, such as tile layout for name generation in Dynamite Soccer (not that it was memorably frustrating or anything).  Worst culprit--at least as far as how much screen time she gets--is Witch.

  There's an unused "All" option when playing chapters from the Extras menu.  It doesn't work in the slightest.  In fact, to make it work you'd have to unhook or conditional every check for the Options menu so it stops skipping the first half of chapters--which are, ironically, the last half of the chapters before them.
  "Ending" though is a valid unlockable option, displaying the credits.  It unlocks, but there isn't a guaranteed save event attached to finishing the game.  Without knowing all the implications of creating one (will it corrupt story state, etc.), leaving that out for the time being.

  Engrish remains in the credits.  "Doraco"'s voice actor must be thrilled.

  Bomb Puyo is still a potato.

-Zoinkity
